package org.gdstash.quest;

import org.gdstash.file.GDReader;
import org.gdstash.util.FileVersionException;
import org.gdstash.util.GDMsgFormatter;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

public class GDQuestList {
    private static final int BLOCK = 11;
    private int version;
    private List<GDQuest> quests;

    public GDQuestList() {
        this.quests = new LinkedList<GDQuest>();
    }

    public void read() throws IOException {
        int val = 0;
        final GDReader.Block block = new GDReader.Block();
        val = GDReader.readBlockStart(block);
        if (val != 11) {
            throw new FileVersionException(GDMsgFormatter.getString(GDMsgFormatter.rbMsg, "ERR_UNSUPPORTED_VERSION"));
        }
        this.version = GDReader.readEncInt(true);
        if (this.version != 3) {
            throw new FileVersionException(GDMsgFormatter.getString(GDMsgFormatter.rbMsg, "ERR_UNSUPPORTED_VERSION"));
        }
        this.quests.clear();
        val = GDReader.readEncInt(true);
        for (int i = 0; i < val; ++i) {
            final GDQuest quest = new GDQuest();
            quest.read();
            this.quests.add(quest);
        }
        GDReader.readBlockEnd(block);
    }
}
